package com.cross.cfg;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Document;

public class CrossSessionFactoryImpl implements CrossSessionFactory {
	private static CrossSessionFactory crossSessionFactory;

	private Map<Class, CrossSession> crossMap = new HashMap<Class, CrossSession>();

	public CrossSessionFactoryImpl() {

	}

	/**
	 * 
	 * 
	 * Mar 19, 2009
	 * 
	 * @author craziness_stone
	 * @return
	 */
	public static CrossSessionFactory getInstance() {
		if (null == crossSessionFactory) {
			crossSessionFactory = new CrossSessionFactoryImpl();
		}
		return crossSessionFactory;
	}

	public CrossSession getCrossSession(Class clazz) throws Exception {
		CrossSession session = crossMap.get(clazz);
		if (null == session) {
			session = create(clazz);
			if (null == session) {
				throw new Exception("no cross.xml");
			}
			crossMap.put(clazz, session);
		}
		return crossMap.get(clazz);
	}

	private CrossSession create(Class clazz) {
		File file = getConfigFile(clazz);
		Document document = getConfigDocument(file);
		return buildCrossSession(document);
	}

	private File getConfigFile(Class clazz) {

		return null;
	}

	private Document getConfigDocument(File file) {
		return null;
	}

	private CrossSession buildCrossSession(Document document) {

		return null;
	}
}
